package cn.epsilon3.common;

import com.alibaba.fastjson.JSONObject;
import cn.epsilon3.domain.e3.po.AccountInfo;
import cn.epsilon3.exception.Epsilon3Exception;
import cn.epsilon3.utils.SecurityUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @description response 写入
 *
 * @author epsilon3
 * @version 1.0
 * @project epsilon3-module-core
 * @date 2023/08/09
 */
public class ResultResp {

    /**
     * response 返回
     *
     * @param response
     * @param code
     * @param message
     */
    public static void resp(HttpServletResponse response,
                                Integer code,
                                String message) {
        AccountInfo accountInfo = SecurityUtils.currentAccount();
        PrintWriter printWriter = null;
        try {
            printWriter = response.getWriter();
        } catch (Exception e) {
            throw new Epsilon3Exception("response.getWriter error:" + e.getMessage());
        }
        JSONObject res = new JSONObject();
        res.put("code", code);
        res.put("message", message);
        printWriter.append(res.toString());
    }
}
